package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 应用模块名称<p>
 * 代码描述<p>
 * Company: 逍邦网络科技有限公司<p>
 *
 * @author chenshan
 * @version v1.0
 * @since 2019-11-13 21:01
 */
@Getter
public enum ManagementButtomEnum {
	CUSTOMER_PAYMENT_SHEET(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "paymentSheet", "enum.paymentManagementButtom.value.customer_payment_sheet", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias()),
	CUSTOMER_PAYMENT(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "payment", "enum.paymentManagementButtom.value.customer_payment", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAYMENT.getCode(), ProPermissionAliasEnum.PAYMENT_ADD.getAlias()),

	CONTRACT_PAYMENT(XbbRefTypeEnum.CONTRACT.getCode(),"payment","enum.paymentManagementButtom.value.contract_payment",OperateTypeEnum.NEW.getAlias(),XbbRefTypeEnum.PAYMENT.getCode(), ProPermissionAliasEnum.PAYMENT_ADD.getAlias()),
	CONTRACT_PAYMENT_SHEET(XbbRefTypeEnum.CONTRACT.getCode(), "paymentSheet", "enum.paymentManagementButtom.value.contract_payment_sheet", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias()),
	CONTRACT_WRITE_OFF_PERPAYMENT(XbbRefTypeEnum.CONTRACT.getCode(), "writeOffPrepayment", "enum.paymentManagementButtom.value.contract_write_off_perpayment", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.WRITE_OFF_PREPAYMENT.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias()),
	CONTRACT_BAD_BAT(XbbRefTypeEnum.CONTRACT.getCode(), "badDebt", "enum.paymentManagementButtom.value.contract_bad_bat", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.BAD_DEBT.getCode(),ProPermissionAliasEnum.PAYMENT_SHEET_BAD.getAlias()),
	/**
	 * 校正合同的已收、未收金额用的，与按钮权限无关
	 */
	CONTRACT_FIX(XbbRefTypeEnum.CONTRACT.getCode(), "contractFix", "enum.paymentManagementButtom.value.contract_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.CONTRACT.getCode(), ProPermissionAliasEnum.CONTRACT.getAlias()),

	SUPPLIER_PAY_SHEET(XbbRefTypeEnum.SUPPLIER.getCode(), "paySheet", "enum.paymentManagementButtom.value.supplier_pay_sheet", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAY_SHEET.getCode(), ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias()),
	SUPPLIER_PAY_PLAN(XbbRefTypeEnum.SUPPLIER.getCode(), "payPlan", "enum.paymentManagementButtom.value.supplier_pay_plan", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAY_PLAN.getCode(), ProPermissionAliasEnum.PAY_PLAN_ADD.getAlias()),

	PURCHASE_PAY_PLAN(XbbRefTypeEnum.PURCHASE.getCode(),"payPlan","enum.paymentManagementButtom.value.purchase_pay_plan",OperateTypeEnum.NEW.getAlias(),XbbRefTypeEnum.PAY_PLAN.getCode(), ProPermissionAliasEnum.PAY_PLAN_ADD.getAlias()),
	PURCHASE_PAY_SHEET(XbbRefTypeEnum.PURCHASE.getCode(), "paySheet", "enum.paymentManagementButtom.value.purchase_pay_sheet", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.PAY_SHEET.getCode(), ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias()),
	PURCHASE_WRITE_OFF_PERPAY(XbbRefTypeEnum.PURCHASE.getCode(), "writeOffPrepay", "enum.paymentManagementButtom.value.purchase_write_off_perpay", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.WRITE_OFF_PREPAY.getCode(), ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias()),
	PURCHASE_BAD_PAY(XbbRefTypeEnum.PURCHASE.getCode(), "badPay", "enum.paymentManagementButtom.value.purchase_bad_pay", OperateTypeEnum.NEW.getAlias(), XbbRefTypeEnum.BAD_PAY.getCode(),ProPermissionAliasEnum.PAY_SHEET_BAD.getAlias()),
	PURCHASE_FIX(XbbRefTypeEnum.PURCHASE.getCode(), "purchaseFix", "enum.paymentManagementButtom.value.purchase_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.PURCHASE.getCode(),ProPermissionAliasEnum.PURCHASE.getAlias()),

	/**
	 * 校正回款计划（应收款）
	 */
	PAYMENT_PAYMENT_SHEET_FIX(XbbRefTypeEnum.PAYMENT.getCode(), "paymentFix", "enum.paymentManagementButtom.value.payment_payment_sheet_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(), ProPermissionAliasEnum.PAYMENT.getAlias()),
	/**
	 * 校正付款计划（应收款）
	 */
	PAY_PAY_SHEET_FIX(XbbRefTypeEnum.PAY_PLAN.getCode(), "payFix", "enum.paymentManagementButtom.value.pay_pay_sheet_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.PAY_SHEET.getCode(), ProPermissionAliasEnum.PAY_PLAN.getAlias()),

	/**
	 * 校正预收款（客户）
	 */
	PREPAYMENT_BALANCE_FIX(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), "prepaymentBalanceFix", "enum.paymentManagementButtom.value.pay_pay_sheet_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(), ProPermissionAliasEnum.PAYMENT_SHEET_VIEW.getAlias()),

	/**
	 * 校正预付款（供应商）
	 */
	PREPAY_BALANCE_FIX(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), "prepayBalanceFix", "enum.paymentManagementButtom.value.pay_pay_sheet_fix", OperateTypeEnum.DATA_FIX.getAlias(), XbbRefTypeEnum.PAY_SHEET.getCode(), ProPermissionAliasEnum.PAY_SHEET_VIEW.getAlias()),

	;
	/**
	 * 来自哪个详情的tab
	 */
	private Integer fromBusinessType;
	/**
	 * 别称
	 */
	private String attr;
	/**
	 * 显示值
	 */
	private String value;
	/**
	 * button类型
	 */
	private String btuType;
	/**
	 * 关联业务类型
	 */
	private Integer businessType;
	
	private String permission;
	
	ManagementButtomEnum(Integer fromBusinessType, String attr, String value, String btuType, Integer businessType, String permission) {
		this.fromBusinessType = fromBusinessType;
		this.attr = attr;
		this.value = value;
		this.btuType = btuType;
		this.businessType = businessType;
		this.permission = permission;
	}
	
	public static List<ManagementButtomEnum> getButtomList(XbbRefTypeEnum xbbRefTypeEnum) {
		List<ManagementButtomEnum> paymentManagementButtomEnumList = new ArrayList<>();
		for ( ManagementButtomEnum buttomEnum : values() ) {
			if ( Objects.equals(xbbRefTypeEnum.getCode(), buttomEnum.getFromBusinessType())) {
				paymentManagementButtomEnumList.add(buttomEnum);
			}
		}
		return paymentManagementButtomEnumList;
	}

	/**
	 * 获取不需要权限过滤的按钮
	 *
	 * @return
	 */
	public static List<ManagementButtomEnum> getNoPerLimitButtomList() {
		return Arrays.asList(ManagementButtomEnum.CONTRACT_FIX);
	}

	public String getValue() {
		return I18nMessageUtil.getMessage(value);
	}

}
